package com.firefly.admin.monitor.jobclass;

import com.firefly.admin.common.constant.Constants;
import com.firefly.admin.monitor.entity.FyMonitorJob;
import lombok.extern.slf4j.Slf4j;
import com.firefly.admin.monitor.vo.JobExecuteResult;
import org.springframework.stereotype.Component;

import java.util.Random;

@Component
@Slf4j
public class CleanLogJobService {
    public JobExecuteResult cleanLog(FyMonitorJob monitorJob) {
        log.info("#########CleanLogJobService cleanLog job start !");
        JobExecuteResult jobExecuteResult = new JobExecuteResult();
        String jobName = monitorJob.getJobName();
        int i = new Random().nextInt(3);
        if (i == 1) {
            log.info("#########定时任务[{}]执行成功！！！", jobName);
            jobExecuteResult.setExecuteResult(Constants.LastExecuteResult.SUCCESS);
        } else if (i == 2) {
            log.info("#########定时任务[{}]执行失败！！！", jobName);
            jobExecuteResult.setExecuteResult(Constants.LastExecuteResult.FAIL);
            jobExecuteResult.setErrorMsg("测试失败结果");
        } else {
            log.info("#########定时任务[{}]未执行！！！", jobName);
            jobExecuteResult.setExecuteResult(Constants.LastExecuteResult.NOT_EXECUTED);
        }
        log.info("#########CleanLogJobService cleanLog job end !");
        return jobExecuteResult;
    }
}
